<?php


namespace App\Libraries\CustomsBills\Data;


use App\Libraries\CustomsBills\Contracts\Message;
use App\Libraries\CustomsBills\Data\CEB311Message\OrderList;
use App\Libraries\CustomsBills\Assert;

class CEB311Message extends Message
{
    /**
     * 收货人电话号码
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $consigneeTelephone;
    /**
     * 订购人姓名
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $buyerName;
    /**
     * 订购人平台账号
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $buyerRegNo;
    /**
     * 订单号
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $orderNo;
    /**
     * 电商企业代码
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $ebcCode;
    /**
     * 电商平台代码
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $ebpCode;
    /**
     * 电商企业名称
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $ebcName;
    /**
     * 电商平台名称
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $ebpName;
    /**
     * @var float
     * @author luffyzhao@vip.126.com
     */
    protected $goodsValue;
    /**
     * 物流费用
     * @var float
     * @author luffyzhao@vip.126.com
     */
    protected $freight;
    /**
     * 非现金折扣
     * @var float
     * @author luffyzhao@vip.126.com
     */
    protected $discount;
    /**
     * 税费
     * @var float
     * @author luffyzhao@vip.126.com
     */
    protected $taxTotal;
    /**
     * 支付金额
     * @var float
     * @author luffyzhao@vip.126.com
     */
    protected $acturalPaid;
    /**
     * 订购人电话号码
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $buyerTelephone;
    /**
     * 订购人身份证
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $buyerIdNumber;
    /**
     * 收货人
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $consignee;
    /**
     * 收货人地址
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $consigneeAddress;
    /**
     * 订单产品信息
     * @var OrderList[]
     * @author luffyzhao@vip.126.com
     */
    protected $orderList;

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getConsigneeTelephone(): string
    {
        Assert::notEmpty($this->consigneeTelephone, '收货人电话 不能为空');
        Assert::maxLength($this->consigneeTelephone, 60, '收货人电话 最大长度 %s');
        return $this->consigneeTelephone;
    }

    /**
     * @param string $consigneeTelephone
     * @author luffyzhao@vip.126.com
     */
    public function setConsigneeTelephone(string $consigneeTelephone): void
    {
        $this->consigneeTelephone = $consigneeTelephone;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getBuyerName(): string
    {
        Assert::notEmpty($this->buyerName, '收货人姓名 不能为空');
        Assert::maxLength($this->buyerName, 60, '收货人姓名 最大长度 %s');
        return $this->buyerName;
    }

    /**
     * @param string $buyerName
     * @author luffyzhao@vip.126.com
     */
    public function setBuyerName(string $buyerName): void
    {
        $this->buyerName = $buyerName;
    }

    /**
     * @param string $buyerRegNo
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setBuyerRegNo(string $buyerRegNo): CEB311Message
    {
        $this->buyerRegNo = $buyerRegNo;
        return $this;
    }

    /**
     * @param string $orderNo
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setOrderNo(string $orderNo): CEB311Message
    {
        $this->orderNo = $orderNo;
        return $this;
    }

    /**
     * @param string $ebcCode
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setEbcCode(string $ebcCode): CEB311Message
    {
        $this->ebcCode = $ebcCode;
        return $this;
    }

    /**
     * @param string $ebpCode
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setEbpCode(string $ebpCode): CEB311Message
    {
        $this->ebpCode = $ebpCode;
        return $this;
    }

    /**
     * @param string $ebcName
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setEbcName(string $ebcName): CEB311Message
    {
        $this->ebcName = $ebcName;
        return $this;
    }

    /**
     * @param string $ebpName
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setEbpName(string $ebpName): CEB311Message
    {
        $this->ebpName = $ebpName;
        return $this;
    }

    /**
     * @param float $goodsValue
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setGoodsValue(float $goodsValue): CEB311Message
    {
        $this->goodsValue = $goodsValue;
        return $this;
    }

    /**
     * @param float $freight
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setFreight(float $freight): CEB311Message
    {

        $this->freight = $freight;
        return $this;
    }

    /**
     * @param float $discount
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setDiscount(float $discount): CEB311Message
    {
        $this->discount = $discount;
        return $this;
    }

    /**
     * @param float $acturalPaid
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setActuralPaid(float $acturalPaid): CEB311Message
    {
        $this->acturalPaid = $acturalPaid;
        return $this;
    }

    /**
     * @param float $taxTotal
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setTaxTotal(float $taxTotal): CEB311Message
    {
        $this->taxTotal = $taxTotal;
        return $this;
    }

    /**
     * @param string $buyerTelephone
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setBuyerTelephone(string $buyerTelephone): CEB311Message
    {
        $this->buyerTelephone = $buyerTelephone;
        return $this;
    }

    /**
     * @param string $buyerIdNumber
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setBuyerIdNumber(string $buyerIdNumber): CEB311Message
    {
        $this->buyerIdNumber = $buyerIdNumber;
        return $this;
    }

    /**
     * @param string $consignee
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setConsignee(string $consignee): CEB311Message
    {
        $this->consignee = $consignee;
        return $this;
    }

    /**
     * @param string $consigneeAddress
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function setConsigneeAddress(string $consigneeAddress): CEB311Message
    {
        $this->consigneeAddress = $consigneeAddress;
        return $this;
    }

    /**
     * @param OrderList $orderList
     * @return CEB311Message
     * @author luffyzhao@vip.126.com
     */
    public function addOrderList(OrderList $orderList): CEB311Message
    {
        $this->orderList[] = $orderList;
        return $this;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getEbcCode(): string
    {
        Assert::length($this->ebcCode, 10, "电商企业代码 固定长度10个字符");
        return $this->ebcCode;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getBuyerRegNo(): string
    {
        return $this->buyerRegNo;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getOrderNo(): string
    {
        Assert::notEmpty($this->orderNo, '订单号 不能为空');
        Assert::maxLength($this->orderNo, 60, '订单号 最大长度 %s');
        return $this->orderNo;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getEbpCode(): string
    {
        Assert::length($this->ebpCode, 10, "电商平台代码 固定长度10个字符");
        return $this->ebpCode;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getEbcName(): string
    {
        Assert::notEmpty($this->ebcName, '电商企业名称 必须填写');
        Assert::maxLength($this->ebcName, 100, "电商企业名称 固定长度10个字符");
        return $this->ebcName;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getEbpName(): string
    {
        Assert::notEmpty($this->ebpName, '电商平台名称 必须填写');
        Assert::maxLength($this->ebpName, 100, "电商平台名称 固定长度100个字符");
        return $this->ebpName;
    }

    /**
     * @return float
     * @author luffyzhao@vip.126.com
     */
    public function getGoodsValue(): float
    {
        Assert::floatAndRadixLength($this->goodsValue, 19, 5, "商品货值 格式 N19,5");
        return $this->goodsValue;
    }

    /**
     * @return float
     * @author luffyzhao@vip.126.com
     */
    public function getFreight(): float
    {
        Assert::floatAndRadixLength($this->freight, 19, 5, "运费 格式 N19,5");
        return $this->freight;
    }

    /**
     * @return float
     * @author luffyzhao@vip.126.com
     */
    public function getDiscount(): float
    {
        Assert::floatAndRadixLength($this->discount, 19, 5, "非现金折扣 格式 N19,5");
        return $this->discount;
    }

    /**
     * @return float
     * @author luffyzhao@vip.126.com
     */
    public function getTaxTotal(): float
    {
        Assert::floatAndRadixLength($this->taxTotal, 19, 5, "税费 格式 N19,5");
        return $this->taxTotal;
    }

    /**
     * @return float
     * @author luffyzhao@vip.126.com
     */
    public function getActuralPaid(): float
    {
        Assert::floatAndRadixLength($this->acturalPaid, 19, 5, "支付金额 格式 N19,5");
        return $this->acturalPaid;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getBuyerTelephone(): string
    {
        Assert::notEmpty($this->buyerTelephone, "订购人联系方式 不能为空");
        Assert::maxLength($this->buyerTelephone, 30, "订购人联系方式 最大长度为 30 个字符");
        return $this->buyerTelephone;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getBuyerIdNumber(): string
    {
        Assert::notEmpty($this->buyerIdNumber, "订购人身份证信息 不能为空");
        Assert::maxLength($this->buyerIdNumber, 60, "订购人身份证信息 最大长度为 30 个字符");
        return $this->buyerIdNumber;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getConsignee(): string
    {
        Assert::notEmpty($this->consignee, "订购人姓名 不能为空");
        Assert::maxLength($this->consignee, 100, "订购人姓名 最大长度为 100 个字符");
        return $this->consignee;
    }

    /**
     * @return OrderList[]
     * @author luffyzhao@vip.126.com
     */
    public function getOrderList(): array
    {
        return $this->orderList;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getConsigneeAddress(): string
    {
        Assert::notEmpty($this->consigneeAddress, "订购人地址 不能为空");
        Assert::maxLength($this->consigneeAddress, 200, "订购人地址 最大长度为 200 个字符");
        return $this->consigneeAddress;
    }


    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function __toString()
    {
        return <<<Order
<ceb:Order>
<ceb:OrderHead>
    <ceb:guid>{$this->getUUid()}</ceb:guid>
    <ceb:appType>2</ceb:appType>
    <ceb:appTime>{$this->getAppTime()}</ceb:appTime>
    <ceb:appStatus>2</ceb:appStatus>
    <ceb:orderType>I</ceb:orderType>
    <ceb:orderNo>{$this->getOrderNo()}</ceb:orderNo>
    <ceb:ebpCode>{$this->getEbpCode()}</ceb:ebpCode>
    <ceb:ebpName>{$this->getEbpName()}</ceb:ebpName>
    <ceb:ebcCode>{$this->getEbcCode()}</ceb:ebcCode>
    <ceb:ebcName>{$this->getEbcName()}</ceb:ebcName>
    <ceb:goodsValue>{$this->getGoodsValue()}</ceb:goodsValue>
    <ceb:freight>{$this->getFreight()}</ceb:freight>
    <ceb:discount>{$this->getDiscount()}</ceb:discount>
    <ceb:taxTotal>{$this->getTaxTotal()}</ceb:taxTotal>
    <ceb:acturalPaid>{$this->getActuralPaid()}</ceb:acturalPaid>
    <ceb:currency>142</ceb:currency>
    <ceb:buyerRegNo>{$this->getBuyerRegNo()}</ceb:buyerRegNo>
    <ceb:buyerName>{$this->getBuyerName()}</ceb:buyerName>
    <ceb:buyerTelephone>{$this->getBuyerTelephone()}</ceb:buyerTelephone>
    <ceb:buyerIdType>1</ceb:buyerIdType>
    <ceb:buyerIdNumber>{$this->getBuyerIdNumber()}</ceb:buyerIdNumber>
    <ceb:consignee>{$this->getConsignee()}</ceb:consignee>
    <ceb:consigneeTelephone>{$this->getConsigneeTelephone()}</ceb:consigneeTelephone>
    <ceb:consigneeAddress>{$this->getConsigneeAddress()}</ceb:consigneeAddress>
</ceb:OrderHead>
{$this->getImplode($this->getOrderList())}
</ceb:Order>
Order;

    }
}